package com.example.controller.medical;


import cn.hutool.core.lang.Dict;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.Result;
import com.example.model.dto.HospitalDto;
import com.example.model.entity.medical.Hospital;
import com.example.model.vo.HospitalVO;
import com.example.service.medical.HospitalService;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 医院表前端操作接口
 **/
@RestController
@RequestMapping("/hospital")
@Api(tags = "医院接口")
public  class HospitalController {

    @Resource
    private HospitalService hospitalService;


    /**
     * 查询挂号量靠前的医院
     * @return
     */
    @ApiOperation(value = "查询挂号量靠前的医院")
    @GetMapping("/selectTopHospital")
    public Result getTopHospitals() {
        List<HospitalVO> list = hospitalService.selectTopHospitals();
        return Result.success(list);
    }

    /**
     * 根据信息查询医院
     * @param hospitalDto 医院信息
     * @return
     */
    @ApiOperation(value = "根据信息查询医院")
    @PostMapping("/selectHospitalPage")
    public Result selectHospitalByInfo(@RequestBody HospitalDto hospitalDto) {
        PageInfo<Hospital> list = hospitalService.selectHospitalByInfo(hospitalDto);
        return Result.success(list);
    }

    /**
     * 新增
     */
    @ApiOperation(value = "新增医院")
    @PostMapping("/add")
    public Result add(@RequestBody Hospital Hospital) {
        hospitalService.add(Hospital);
        return Result.success();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除医院")
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        hospitalService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量修改
     */
    @ApiIgnore
    @PutMapping("/updateBatch")
    public Result updateBatch(@RequestBody HospitalDto hospitalDto) {
        hospitalService.updateBatch(hospitalDto);
        return Result.success();
    }
    /**
     * 批量删除
     */
    @ApiOperation(value = "批量删除医院")
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        hospitalService.deleteBatch(ids);
        return Result.success();
    }
    /**
     * 根据城市查询
     */
    @ApiOperation(value = "根据城市查询医院")
    @GetMapping("/selectByCity")
    public Result selectByCity(@RequestParam String city) {
        List<Hospital> hospitalList = hospitalService.selectByCity(city);
        return Result.success(hospitalList);
    }
    /**
     * 修改
     */
    @ApiOperation(value = "修改医院")
    @PutMapping("/update")
    public Result updateById(@RequestBody Hospital Hospital) {
        hospitalService.updateById(Hospital);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @ApiOperation(value = "根据ID查询医院")
    @GetMapping("/selectById")
    public Result selectById(@RequestParam Integer id) {
        Hospital Hospital = hospitalService.selectById(id);
        return Result.success(Hospital);
    }

    /**
     * 查询所有
     */
    @ApiOperation(value = "查询所有医院")
    @GetMapping("/selectAll")
    public Result selectAll(Hospital Hospital) {
        List<Hospital> list = hospitalService.selectAll(Hospital);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @ApiOperation(value = "分页查询医院")
    @GetMapping("/selectPage")
    public Result selectPage(Hospital Hospital,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Hospital> page = hospitalService.selectPage(Hospital, pageNum, pageSize);
        return Result.success(page);
    }
    /**
     * 医院医生预约排行统计
     */
    @GetMapping("/selectBar")
    public Result selectBar() {
        List<Dict> dictList=hospitalService.selectBar();
        return Result.success(dictList);
    }
}
